import path from "path";
import { defineConfig } from "vite";

export default defineConfig({
  plugins: [],
  resolve: {
    alias: {
      "@": path.resolve(__dirname, "./src"),
    },
  },
  build: {
    lib: {
      entry: ["./src/content/content.ts", "./src/background/background.ts"],
      name: "buildLibrary",
      formats: ["es"],
      fileName: (format, entryName) => `${entryName}/index.js`,
    },
    outDir: "extensions/firefox",
    copyPublicDir: true,
    watch: {
      include: "src/**" 
    },
    rollupOptions: {
      output: {
        // 将入口文件改为 .mjs
        entryFileNames: `[name].js`,
        // 将代码分割的 chunk 文件改为 .mjs
        chunkFileNames: `[name].js`,
        // 资源文件（如图片、字体）保持原名
        assetFileNames: `[name].[ext]`
      }
    }
  },
  publicDir: "./src/firefox",

});
